package com.demo.mq.rocket.provider.simple;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

import static com.demo.mq.rocket.provider.Const.ROCKET_DEFAULT_GROUP;
import static com.demo.mq.rocket.provider.Const.ROCKET_NAMESRVADDR;

/**
 * UDP:只管发送
 */
public class OnewayProducer {

    public static void main(String[] args) throws Exception {

        DefaultMQProducer producer = new DefaultMQProducer(ROCKET_DEFAULT_GROUP);
        producer.setNamesrvAddr(ROCKET_NAMESRVADDR);

        producer.setSendMsgTimeout(10000);

        producer.start();
        for (int i = 0; i < 100; i++) {
            Message msg = new Message("simple_topic",
                    "tags",
                    "keys",
                    ("消息内容" + i).getBytes(StandardCharsets.UTF_8)
            );
            producer.sendOneway(msg);
        }
        Thread.sleep(5000);
        producer.shutdown();
    }

}
